package org.hawk.gwt.ppc.parser;

/**
 * Represents some string, character or digit literal.
 * Not all literals in java language are represented as this interface.
 * Here is only source-level literals - strings, numbers and characters.
 * 
 * @author alex.bereznevatiy@gmail.com
 *
 */
public interface LiteralExpressionDescriptor extends ExpressionDescriptor {
	
	/**
	 * @return type of this literal. One of:
	 * <ul>
	 * <li>java.lang.String</li>
	 * <li>char</li>
	 * <li>int</li>
	 * <li>float</li>
	 * <li>double</li>
	 * <li>long</li>
	 * </ul>
	 */
	Class<?> getType();
	
	/**
	 * @return string presentation of this literal.
	 */
	String asString();
	
	/**
	 * @return character presentation of this literal 
	 * @throws IllegalStateException if this literal is not a character literal.
	 */
	char asChar() throws IllegalStateException;
	
	/**
	 * @return this literal as integer.
	 * @throws NumberFormatException in case literal cannot be represented as int type.
	 */
	int asInt() throws NumberFormatException;

	/**
	 * @return this literal as float.
	 * @throws NumberFormatException in case literal cannot be represented as float type.
	 */
	float asFloat() throws NumberFormatException;

	/**
	 * @return this literal as double.
	 * @throws NumberFormatException in case literal cannot be represented as double type.
	 */
	double asDouble() throws NumberFormatException;
	
	/**
	 * @return this literal as long.
	 * @throws NumberFormatException in case literal cannot be represented as long type.
	 */
	long asLong() throws NumberFormatException;
}
